< previous page page_819 next page >

Page 819
Creating a Table with DDL Statements
To create a table with the DDL statements, you create a SQL statement containing the name of the table and the names, types, and sizes of each field in the table. The following code shows how to create the Orders table of the sample case:
CREATE TABLE Orders (Orderno LONG, Custno LONG, SalesID TEXT (6), _
    OrderDate DATE, Totcost SINGLE)
Notice that when you specify the table name and field names, you do not have to enclose the names in quotation marks. However, if you want to specify a name with a space in it, you must enclose the name in square brackets (for example, [Last name]).
When you create a table, you can specify only the field names, types, and sizes. You can't specify optional parameters such as default values, validation rules, or validation error messages. Even with this limitation, the DDL CREATE TABLE statement is a powerful tool that you can use to create many of the tables in a database.
Modifying a Table
By using the ALTER TABLE statement, you can add a field to an existing table or delete a field from the table. When adding a field, you must specify the name, type, and (when applicable) the size of the field. You add a field using the ADD COLUMN clause of the ALTER TABLE statement. To delete a field, you only need to specify the field name and use the DROP COLUMN clause of the statement. As with other database-modification methods, you can't delete a field used in an index or a relation. Listing C.20 shows how to add and then delete a field from the Orders table created in the preceding section.
Listing C.20 ALTERTAB.TXTUsing the ALTER TABLE Statement to Add or Delete a Field from a Table
'**************************************************
'Add a shipping charges field to the "Orders" table
'**************************************************
ALTER TABLE Orders ADD COLUMN Shipping SINGLE
'*********************************
'Delete the shipping charges field
'*********************************
ALTER TABLE Orders DROP COLUMN Shipping
Deleting a Table
You can delete a table from a database using the DROP TABLE statement. The following simple piece of code shows how to get rid of the Orders table. Use caution when deleting a table; the table and all its data are gone forever after the command has been executed.
DROP TABLE Orders
Defining Indexes with DDL Statements
Two DDL statements are designed especially for use with indexes:
CREATE INDEXDefines a new index for a table
DROP INDEXDeletes an index from a table

 
< previous page page_819 next page >